package com.hjqjl.module_home.widget;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.blankj.utilcode.util.StringUtils;
import com.hjqjl.module_home.R;

public class HomeTitleLayout extends LinearLayout {
    public HomeTitleLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.home_layout_custom_title, this);
        isInEditMode();
        Button titleBack = findViewById(R.id.home_btn_customTitle_back);
        Button titleEdit = findViewById(R.id.home_btn_customTitle_edit);
        titleBack.setOnClickListener(v -> ((Activity) getContext()).finish());
        titleEdit.setOnClickListener(v -> Toast.makeText(getContext(), "You clicked Edit button", Toast.LENGTH_SHORT).show());


        TextView tvCustomTitle = findViewById(R.id.home_tv_customTitle_text);
        // 将属性值设置到控件中
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HomeTitleLayout);
        CharSequence text = a.getText(R.styleable.HomeTitleLayout_home_title);
        if (text != null && !StringUtils.isEmpty(text.toString().trim())) {
            tvCustomTitle.setText(text);
        }
        a.recycle();
    }
}